#import "TxLivePlugin.h"

#import "TxLiveFactory.h"

#import <TXLiteAVSDK_Professional/TXLiveBase.h>

@implementation TxLivePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"com.notary.tx_live_plugin"
            binaryMessenger:[registrar messenger]];
  TxLivePlugin* instance = [[TxLivePlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
    
    TxLiveFactory* factory = [[TxLiveFactory alloc]initWithMessenger:[registrar messenger]];
    [registrar registerViewFactory:factory withId:@"com.notary.tx_live_plugin/tx_live_plugin"];
    
    // 关闭打印日志
    [TXLiveBase setConsoleEnabled:NO];
    
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if ([@"init" isEqualToString:call.method]) {
      if ([call.arguments isKindOfClass:NSDictionary.class]) {
          NSString *licenceKey,*licenseURL;
          if ([[call.arguments allKeys] containsObject:@"licenceKey"]) {
              licenceKey = call.arguments[@"licenceKey"];
          }
          if ([[call.arguments allKeys] containsObject:@"licenseURL"]) {
              licenseURL = call.arguments[@"licenseURL"];
          }
          
          if (licenceKey!=nil && licenseURL!=nil) {
              [TXLiveBase setLicenceURL:licenseURL key:licenceKey];
          }
      }
      if (result) {
          result([NSNumber numberWithBool:YES]);
      }
  } else {
    result(FlutterMethodNotImplemented);
  }
}

@end
